/*
Related Post with Thumbnail & Summary 1.0 (May 02, 2011)
copyright (c) 2011 Hendriono from http://modification-blog.blogspot.com/
*/
var reljudul = new Array();
var relurls = new Array();
var relcuplikan = new Array();
var relgambar = new Array();

function saringtags(suchas, panjang) {
    var cuplik = suchas.split("<");
    for (var i = 0; i < cuplik.length; i++) {
        if (cuplik[i].indexOf(">") != -1) {
            cuplik[i] = cuplik[i].substring(cuplik[i].indexOf(">") + 1, cuplik[i].length)
        }
    }
    cuplik = cuplik.join("");
    cuplik = cuplik.substring(0, panjang - 1);
    return cuplik
}
function relpostimgcuplik(json) {
    for (var i = 0; i < json.feed.entry.length; i++) {
        var entry = json.feed.entry[i];
        reljudul[relnojudul] = entry.title.$t;
        postcontent = "";
        if ("content" in entry) {
            postcontent = entry.content.$t
        } else if ("summary" in entry) {
            postcontent = entry.summary.$t
        }
        relcuplikan[relnojudul] = saringtags(postcontent, numchars);
        if ("media$thumbnail" in entry) {
            postimg = entry.media$thumbnail.url
        } else {
            postimg = ""
        }
        relgambar[relnojudul] = postimg;
        for (var k = 0; k < entry.link.length; k++) {
            if (entry.link[k].rel == 'alternate') {
                relurls[relnojudul] = entry.link[k].href;
                break
            }
        }
        relnojudul++
    }
}
function contains(a, e) {
    for (var j = 0; j < a.length; j++) if (a[j] == e) return true;
    return false
}
function artikelterkait() {
    var tmp = new Array(0);
    var tmp2 = new Array(0);
    var tmp3 = new Array(0);
    var tmp4 = new Array(0);
    for (var i = 0; i < relurls.length; i++) {
        if (!contains(tmp, relurls[i])) {
            tmp.length += 1;
            tmp[tmp.length - 1] = relurls[i];
            tmp2.length += 1;
            tmp2[tmp2.length - 1] = reljudul[i];
            tmp3.length += 1;
            tmp3[tmp3.length - 1] = relcuplikan[i];
            tmp4.length += 1;
            tmp4[tmp4.length - 1] = relgambar[i]
        }
    }
    reljudul = tmp2;
    relurls = tmp;
    relcuplikan = tmp3;
    relgambar = tmp4;
    for (var i = 0; i < reljudul.length; i++) {
        var informasi = Math.floor((reljudul.length - 1) * Math.random());
        var tempJudul = reljudul[i];
        var tempUrls = relurls[i];
        var tempCuplikan = relcuplikan[i];
        var tempGambar = relgambar[i];
        reljudul[i] = reljudul[informasi];
        relurls[i] = relurls[informasi];
        relcuplikan[i] = relcuplikan[informasi];
        relgambar[i] = relgambar[informasi];
        reljudul[informasi] = tempJudul;
        relurls[informasi] = tempUrls;
        relcuplikan[informasi] = tempCuplikan;
        relgambar[informasi] = tempGambar
    }
    var rangkumanPosts = 0;
    var r = Math.floor((reljudul.length - 1) * Math.random());
    var rini = r;
    var relhasil;
    var dirURL = document.URL;
    while (rangkumanPosts < relmaxtampil) {
        if (relurls[r] != dirURL) {
            relhasil = "<li class='news-title clearfix'>";
            relhasil += "<a href='" + relurls[r] + "' rel='nofollow'  target='_top' title='" + reljudul[r] + "'><img expr:alt='data:post.snippet' expr:title='data:post.snippet' src='" + relgambar[r] + "' /></a>";
            relhasil += "<a href='" + relurls[r] + "' target='_top'>" + reljudul[r] + "</a>";
            relhasil += "</li>";
            document.write(relhasil);
            rangkumanPosts++;
            if (rangkumanPosts == relmaxtampil) {
                break
            }
        }
        if (r < reljudul.length - 1) {
            r++
        } else {
            r = 0
        }
        if (r == rini) {
            break
        }
    }
}